import { SpriteFrame } from "cc"
import { Sprite } from "cc"
import { Tween } from "cc"
import { _decorator, Component, Node } from "cc"
const { ccclass, property } = _decorator

@ccclass("AniBossComing")
export class AniBossComing extends Component {
  @property(Node)
  nodeMask: Node = null!

  @property(Node)
  nodeOther: Node = null!

  @property(Node)
  nodeUp: Node = null!

  @property(Node)
  nodeDown: Node = null!

  @property(Node)
  nodeCenter: Node = null!

  @property(Node)
  nodeSj: Node = null!

  @property(Node)
  nodeTextBoss: Node = null!

  @property(Node)
  nodeArrow1: Node = null!

  @property(Node)
  nodeArrow2: Node = null!

  @property(Node)
  nodeArrow3: Node = null!

  @property([SpriteFrame])
  arrSprFrameBossComing:SpriteFrame[] = []

  init(index:number){
    const sprite = this.nodeTextBoss.getComponent(Sprite)
    if(sprite){
      sprite.spriteFrame = this.arrSprFrameBossComing[index]
    }
  }

  start() {
    this.nodeMask.alpha = 0
    this.nodeOther.alpha = 0
    this.nodeSj.alpha = this.nodeArrow1.alpha = this.nodeArrow2.alpha = this.nodeArrow3.alpha = 0

    const time1: number = 0.3
    new Tween(this.nodeMask).to(time1, { alpha: 1 }).start()
    new Tween(this.nodeOther).to(time1, { alpha: 1 }).start()
    this.nodeUp.positionX = this.nodeDown.positionX = this.nodeCenter.positionX = this.nodeTextBoss.positionX = -1100
    this.scheduleOnce(() => {
      const time2: number = 0.22
      new Tween(this.nodeCenter).to(time2 - 0.1, { positionX: 0 }, { easing: "backOut" }).start()
      new Tween(this.nodeUp).to(time2, { positionX: 0 }, { easing: "backOut" }).start()
      new Tween(this.nodeDown).to(time2, { positionX: 0 }, { easing: "backOut" }).start()
      new Tween(this.nodeTextBoss).to(time2, { positionX: 0 }, { easing: "backOut" }).start()
      this.scheduleOnce(() => {
        this.nodeSj.alpha = 0.5
        this.nodeSj.scaleXYZ = 1.1
        new Tween(this.nodeSj)
          .to(0.1, { scaleXYZ: 1 ,alpha:1})
          .call(() => {
            this.nodeArrow1.alpha = this.nodeArrow2.alpha = this.nodeArrow3.alpha = 1
            this.nodeArrow1.scaleXYZ = this.nodeArrow2.scaleXYZ = this.nodeArrow3.scaleXYZ = 0.8
            this.scheduleOnce(() => {
              this.nodeArrow1.scaleXYZ = this.nodeArrow2.scaleXYZ = this.nodeArrow3.scaleXYZ = 1
            }, 0.06)
          })
          .start()
      }, time2)
    }, 0.22)

    this.scheduleOnce(() => {
      new Tween(this.nodeOther).to(0.2, { positionX: 1100 },{easing:"backIn"}).call(()=>{
        this.node.destroy()
      }).start()
    },1 + time1)
  }

  update(deltaTime: number) {}
}
